<template>
	<view style="padding-bottom: 180upx;">

		<view class="bg margin-lr radius margin-top-sm flex padding">
			<image :src="orderList.fixedClassImg" style="width: 149upx;height: 149upx;border-radius: 8upx;"></image>
			<view class="margin-left-sm  ">
				<view class="  text-lg text-bold ">{{orderList.serviceName}}</view>
				<view class="margin-tb-xs" style="color: #999999;">{{orderList.fixedClassifyName}}</view>
				<view>上门时间：{{orderList.deliveryTime}}</view>
			</view>
		</view>

		<view class="bg margin-lr radius margin-top-sm padding">
			<view>服务内容</view>
			<view class="margin-top">{{orderList.content}}</view>
			<view class="flex flex-wrap">
				<view v-for="(ite,ind) in orderList.image" :key="ind" class="margin-top margin-right-sm"
					@click="saveImg(orderList.image,ind)">
					<image :src="ite" style="width: 160upx; height: 160upx;border-radius: 5upx;"></image>
				</view>
			</view>
		</view>

		<view class="flex align-center justify-between bg margin padding radius"
			@tap="bindGps(orderList.latitude,orderList.longitude,orderList.detailsAddress)">
			<view>
				<view class="text-lg text-bold margin-bottom-xs flex align-center">{{orderList.name}}
					<view class="margin-left-sm" @click="bindphone(orderList.phone)">{{orderList.phones}}
						<u-icon name="phone" size="30" color="#999999" style="margin-left: 10rpx;"></u-icon>
					</view>
				</view>
				<view style="color: #999999;width: 550rpx;">{{orderList.detailsAddress}}
				<image src="../../static/images/my/address.png"
					style="width: 32rpx;height:32rpx;margin-left:15rpx;"></image>
				</view>
			</view>
			<image src="../../static/images/index/right.png" style="width: 15upx;height: 28upx;"></image>
		</view>

		<view class="bg margin-lr radius margin-top-sm padding">
			<view class="flex justify-between align-center">
				<view>联系发单人</view>
			</view>
			<view class="flex margin-top-sm">
				<view>
					<image :src="orderList.user.avatar?orderList.user.avatar:'../../static/logo.png'"
						style="width: 88upx;height: 88upx;border-radius: 50upx;"></image>
				</view>
				<view class="margin-left-xs flex align-center justify-between" style="width: 100%;">
					<view>{{orderList.user.userName}}</view>
					<view class="flex align-center ">
						<view @click="goMsg(orderList.userId,orderList.name)">
							<image src="../static/xiaoxi.png" style="width: 60upx;height: 60upx;"></image>
						</view>
						<view @click="bindphone(orderList.user.phone)">
							<image src="../static/phone.png" style="width: 60upx;height: 60upx;margin-left: 25upx;">
							</image>
						</view>
					</view>
				</view>
			</view>
		</view>


		<view class="bg margin-lr radius margin-top-sm padding-tb-sm padding-lr"
			v-for="(item,index) in orderList.biddingList">
			<view class="flex margin-top-sm">
				<view>
					<image :src="item.avatar?item.avatar:'../../static/logo.png'"
						style="width: 88upx;height: 88upx;border-radius: 50upx;"></image>
				</view>
				<view class="margin-left-xs" style="width: 100%;">
					<view>{{item.userName}}</view>
					<view class="flex align-center justify-between">
						<view class="wensheng text-cut">
							联系电话：{{maskPhoneNumber(item.phone)}}
							<!-- <u-icon name="phone"></u-icon> -->
						</view>
						<view class="text-lg text-bold" style="color: #557EFD;">
							报价：{{item.offerMoney}}
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="margin-tb-xs" style="width: 100%;height: 1rpx;background: #f5f5f5;"></view>
			<view class="text-lg text-bold" style="color: #557EFD;">
				报价：{{item.offerMoney}}
			</view> -->
		</view>


		<view class="bg margin-lr radius margin-top-sm padding">
			<view class="text-lg text-bold">订单信息</view>
			<!-- <view class="flex justify-between align-center margin-top">
				<view>订单类型</view>
				<view>{{orderList.serviceName}}</view>
			</view> -->
			<view class="flex justify-between align-center margin-top">
				<view>下单时间</view>
				<view>{{orderList.createTime}}</view>
			</view>
			<view class="flex justify-between align-center margin-top">
				<view>订单编号</view>
				<view @click="copyOrder(orderList.orderNo)">{{orderList.orderNo}}
					<u-icon name="order"></u-icon>
				</view>
			</view>
		</view>
		<view class="tabber" v-if="orderList.status ==3">
			<view class="btn1" @click.stop="cancelOrder(orderList)" v-if="orderList.status ==1">取消订单</view>
			<view class="btn2" @click.stop="openCode(orderList)" v-if="orderList.status ==3">输入确认码</view>
			<view class="btn2" @click.stop="openCode(orderList)" v-if="orderList.status ==1">开始服务</view>
		</view>
		<u-popup v-model="show" mode="center" width="500rpx" height="190px" border-radius="14" closeable="true">
			<view class="padding-lr" style="margin-top: 30upx;">
				<view class="text-lg text-bold margin-bottom">确认码</view>
				<view class=" padding-lr-sm" style="background: #F5F5F5;">
					<u-input v-model="codes" type="number" placeholder="请输入确认码" @confirm="change()" />
					<!-- <input type="number" v-memo="code" placeholder="请输入确认码"/> -->
				</view>
				<view class="btn3" @click="sure()">确认</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				helpOrderId: '',
				orderList: [],
				show: false,
				codes: '',
				helpTakeId: '',
				// helpOrderId: ''
			}

		},
		onLoad(option) {
			console.log(option)
			this.helpOrderId = option.id
			if (this.helpOrderId) {
				this.getorderlist()
			}
		},
		methods: {
			goMsg(byUserId, teamName) {
				let data = {
					userId: uni.getStorageSync('userId'),
					focusedUserId: byUserId,
					userType: 2
				}
				this.$Request.postJson('/app/chat/insertChatConversation', data).then(res => {
					if (res.code == 0) {
						let id = byUserId == res.data.userId ? res.data.focusedUserId : byUserId
						uni.navigateTo({
							url: '/pages/msg/im?chatConversationId=' + res.data.chatConversationId +
								'&byUserId=' + id + '&teamName=' + teamName
						})
					}
				})
			},
			copyOrder(order) {
				let that = this;
				uni.setClipboardData({
					data: order,
					success: function() {
						that.$queue.showToast('复制成功')
					}
				})
			},
			getorderlist() {
				this.$queue.showLoading("加载中...");
				let data = {
					helpOrderId: this.helpOrderId,
					userId: uni.getStorageSync('userId'),
				}
				this.$Request.get("/app/help/selectHelpOrderDetails", data).then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						this.orderList = res.data
						if (this.orderList.serviceName) {
							this.orderList.serviceName = this.orderList.serviceName.split('/')
							this.orderList.serviceName = this.orderList.serviceName[0]
						}
						if (this.orderList.phone) {
							let number = this.orderList.phone
							this.orderList.phones = number.substring(0, 3) + '****' + number.substring(7);
						}
						if (this.orderList.image) {
							this.orderList.image = this.orderList.image.split(',')
						}
					}
				});
			},
			// 输入验证码
			openCode(e) {
				this.show = true
				this.helpTakeId = e.helpTakeId
				this.helpOrderId = e.id
			},
			change(e) {
				this.codes = e
			},
			sure() {
				console.log(this.codes, '000000')
				let data = {
					helpTakeId: this.helpTakeId,
					helpOrderId: this.helpOrderId,
					code: this.codes
				}
				this.$Request.post('/app/help/closeOrder', data).then(res => {
					if (res.code == 0) {
						this.show = false
						this.codes = ''
						uni.navigateBack()
					} else {
						this.show = false
						this.codes = ''
						uni.showToast({
							title: '确认码不正确！',
							icon: 'none',
							duration: 1000
						})
					}
				})
			},
			//加密中间四位
			maskPhoneNumber(phoneNumber) {
				// 将手机号码转换为字符串类型，并根据其长度确定要替换的位数
				if (phoneNumber) {
					phoneNumber = phoneNumber.toString() //先强制转换成字符串类型
					return phoneNumber.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
				}
			
			},
			// 一键导航
			bindGps(latitude, longitude, name) {
				uni.openLocation({
					latitude: latitude - 0, //要去的纬度-地址       
					longitude: longitude - 0, //要去的经度-地址
					name: name, //地址名称
					address: name, //详细地址名称
					success: function() {
						console.log('导航成功');
					},
					fail: function(error) {
						console.log(error)
					}
				});
			},
			// 拨打电话
			bindphone(phone) {
				let that = this

				// uni.showModal({
				// 	title: '提示',
				// 	content: '是否拨打电话',
				// 	success: function(res) {
				// 		if (res.confirm) {
				// 			console.log('用户点击确定', that.phone);
				// 			uni.makePhoneCall({
				// 				phoneNumber: phone //仅为示例
				// 			});
				// 		} else if (res.cancel) {
				// 			console.log('用户点击取消');
				// 		}
				// 	}
				// });
				uni.makePhoneCall({
					phoneNumber: phone //仅为示例
				});
			},
			// 取消订单
			cancelOrder(e) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定取消订单吗？',
					success: function(res) {
						if (res.confirm) {
							let data = {
								id: e.helpTakeId
							}
							that.$Request.post('/app/help/endHelpTake', data).then(res => {
								if (res.code == 0) {
									uni.navigateBack()
								}
							})
						}
					},
				})
			},
		}
	}
</script>

<style>
	page {
		background: #F2F2F2;
	}

	.bg {
		background: #FFFFFF;
	}

	.box {
		flex: 1;
		text-align: center;
	}

	.active {
		background: #F2F5FF;
	}



	.btn {
		background-color: #557EFD;
		border-radius: 8upx;
		width: 90%;
		margin: 0 auto;
		color: #FFFFFF;
		text-align: center;
		padding: 25upx 0;
		position: fixed;
		bottom: 30upx;
		left: 0upx;
		right: 0upx;

	}

	.lianxi {
		background: #557EFD;
		color: #FFFFFF;
		display: inline-table;
		border-radius: 8upx;
		padding: 10upx 15upx;
	}

	.tabber {
		position: fixed;
		bottom: 0upx;
		left: 0upx;
		right: 0upx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20upx 30upx;
	}

	.btn1 {
		width: 330upx;
		height: 78upx;
		background: #D9D9D9;
		border-radius: 16upx;
		color: #FFFFFF;
		text-align: center;
		line-height: 78upx;
	}

	.btn2 {
		width: 330upx;
		height: 78upx;
		background: #557EFD;
		border-radius: 16upx;
		color: #FFFFFF;
		text-align: center;
		line-height: 78upx;
	}

	.btn3 {
		background: #557EFD;
		border-radius: 16upx;
		text-align: center;
		color: #FFFFFF;
		padding: 20rpx 10rpx;
		margin-top: 60rpx;
	}

	.wensheng {
		width: 380rpx;
	}
</style>